#include "Generate_C_std.h"
#include "Pattern_assign_expr_var.h"

// A small tweak on $T = $x;
class Pattern_assign_expr_cast : public Pattern_assign_expr_var
{
public:
	Expr* rhs_pattern()
	{
		rhs = new Wildcard<VARIABLE_NAME>;
		cast = new Wildcard<CAST>;
		return new Cast (cast, rhs);
	}

	void generate_code (Generate_C* gen)
	{
	  if (agn->is_ref)
	    {
	      buf << "TODO(RefCast)" <<endl;
	    }
	  else

	  {
	    Map<string, string> symnames;
	    symnames["array"]		= "IS_ARRAY";
	    symnames["bool"]		= "IS_BOOL";
	    symnames["int"]		= "IS_LONG";
	    symnames["object"]	= "IS_OBJECT";
	    symnames["real"]		= "IS_DOUBLE";
	    symnames["string"]	= "IS_STRING";
	    symnames["unset"]		= "IS_NULL";
	    
		// No other casts are allowed.
	    if (symnames.has (*cast->value->value))
	    {
	      
	      
	      INST (buf, "assign_expr_cast",
		    lhs->value, rhs->value, s(symnames[*cast->value->value]));
	    }
	    else
	      {
		buf << "TODO(";
		buf << *cast->value->value;
		buf <<  ")";
		buf << endl;
	      }
	    }
	}

public:
	Wildcard<CAST>* cast;
};


CREATE(Pattern_assign_expr_cast)
